﻿using ZSZ.Application.IService;
using ZSZ.Core.Entities;
using ZSZ.DTO;
using ZSZ.EntityFramework;

namespace ZSZ.Application.Service
{
    public class AdminLogService :Repository<AdminLogEntity>,IAdminLogService
    {
        public AdminLogService(ZSZDbContext context) : base(context)
        {
        }

        public long AddNew(long adminUserId, string message)
        {
            var log = new AdminLogEntity
            {
                AdminUserId = adminUserId,
                Message = message
            };

            Insert(log);
            return log.Id;
            

        }

        public AdminLogDTO GetById(long id)
        {
            var log = GetOneById(id);
            if (log == null)
            {
                return null;
            }
            else
            {
                AdminLogDTO dto = new AdminLogDTO();
                dto.AdminUserId = log.AdminUserId;
                dto.AdminUserName = log.AdminUser.Name;
                dto.AdminUserPhoneNum = log.AdminUser.PhoneNum;
                dto.CreateDateTime = log.CreateDateTime;
                dto.Id = log.Id;
                dto.Message = log.Message;
                return dto;
            }

        }

        
    }
}
